package Daos;

import Beans.Agenda;
import Beans.Horario;
import Beans.HorarioDoUsuario;
import Beans.Jogador;
import Beans.Jogo;
import Beans.Usuario;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class Mapeador {

    private static AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration();
    private static SessionFactory factory;

    static {
        mapear();
    }

    public static void criarTabelas() {
        new SchemaExport(annotationConfiguration).create(true, true);
    }

    public static void addClass(Class classe) {
        annotationConfiguration.addAnnotatedClass(classe);
    }

    public static void excluirTabelas() {
        new SchemaExport(annotationConfiguration).drop(true, true);
    }

    public static void mapear() {

        addClass(Horario.class);
        addClass(Usuario.class);
        addClass(Jogo.class);
        addClass(Agenda.class);
        addClass(Jogador.class);
        addClass(HorarioDoUsuario.class);
    }

    public static Session getSessao() {
        factory = annotationConfiguration.buildSessionFactory();
        Session sessao = factory.openSession();
        factory.close();
        return sessao;
    }
}
